<template>
  <!-- 班团组织 -->
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <!-- <el-form-item label="组织名称" prop="orgName">
        <el-input
          v-model="queryParams.orgName"
          placeholder="请输入组织名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="系部" prop="unitCode">
        <el-select
          v-model="queryParams.unitCode"
          placeholder="请选择"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="(dict, index) in unitNameList"
            :key="index"
            :label="dict.sponsorName"
            :value="dict.sponsorCode"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="班级" prop="classNo">
        <el-input
          v-model="queryParams.classNo"
          placeholder="请输入班级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年级" prop="grade">
        <el-input
          v-model="queryParams.grade"
          placeholder="请输入年级"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select
          v-model="queryParams.orgStatus"
          placeholder="请选择"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.orgStatus"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"
          >搜索</el-button
        >
        <el-button type="primary" icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <!-- <el-button type="primary" v-hasPermi="['organ:classOrgan:list']" icon="el-icon-key" size="mini" @click="handleAdd(1)">新增本科生班团</el-button> -->
        <el-button
          type="primary"
          v-hasPermi="['organ:classOrgan:list']"
          icon="el-icon-key"
          size="mini"
          @click="handleAdd(5)"
          >批量导入本科生</el-button
        >
        <!-- <el-button type="primary" v-hasPermi="['organ:classOrgan:addGraduate']" icon="el-icon-key" size="mini" @click="handleAdd(2)">新增研究生班团</el-button> -->
        <el-button
          type="primary"
          v-hasPermi="['organ:classOrgan:addGraduate']"
          icon="el-icon-key"
          size="mini"
          @click="handleAdd(4)"
          >批量导入研究生</el-button
        >
        <!-- <el-button type="primary" v-hasPermi="['organ:classOrgan:addGraduate']" icon="el-icon-key" size="mini" @click="handleAdd(3)">同步所有研究生班团</el-button> -->
        <el-dropdown @command="handleCommand" style="margin-left: 10px">
          <el-button type="primary" size="mini" v-hasPermi="['organ:classOrgan:export']"
            >导出任命信息<i class="el-icon-arrow-down el-icon--right"></i
          ></el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              v-for="option in schoolYearList"
              :key="option.schoolYearId"
              :command="option.schoolYearId"
              @click="handleExport"
              >{{ option.schoolYearId }}</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
        <el-dropdown @command="handleImport" style="margin-left: 10px">
          <el-button type="primary" size="mini" v-hasPermi="['organ:classOrgan:import']"
            >导入任命信息<i class="el-icon-arrow-down el-icon--right"></i
          ></el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              v-for="option in schoolYearList"
              :key="option.schoolYearId"
              :command="option.schoolYearId"
              @click="handleImport"
              >{{ option.schoolYearId }}</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
        <el-dropdown @command="setSchoolYear" style="margin-left: 10px">
          <el-button type="primary" size="mini" v-hasPermi="['organ:classOrgan:schoolYear']"
            >学期：{{ curSchoolYear }}<i class="el-icon-arrow-down el-icon--right"></i
          ></el-button>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item
              v-for="option in schoolYearList"
              :key="option.schoolYearId"
              :command="option.schoolYearId"
              >{{ option.schoolYearId }}</el-dropdown-item
            >
          </el-dropdown-menu>
        </el-dropdown>
        <el-button
          style="margin-left: 10px"
          size="mini"
          type="danger"
          @click="handleBatchDelete()"
          v-hasPermi="['organ:classOrgan:batchDeleteOrg']"
          >批量删除</el-button
        >
      </el-form-item>
    </el-form>

    <el-table border v-loading="loading" :data="orgList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" align="center" width="55"> </el-table-column>
      <el-table-column label="班团名称" align="center" prop="orgName" />
      <el-table-column label="系部" align="center" prop="unitName" />
      <!--      <el-table-column label="指导单位编码" align="center" prop="unitCode" /> -->
      <el-table-column label="班级" align="center" prop="classNo" />
      <el-table-column label="年级" align="center" prop="grade" />
      <!--      <el-table-column label="类型" align="center" prop="type" /> -->
      <el-table-column label="辅导员" align="center">
        <template slot-scope="scope">
          {{ scope.row.teacherName }}<br />{{ scope.row.teacherId }}
        </template>
      </el-table-column>
      <el-table-column label="团支部书记" align="center">
        <template slot-scope="scope">
          {{ scope.row.studentName }}<br />{{ scope.row.studentId }}
        </template>
      </el-table-column>
      <el-table-column label="审核情况" align="center" prop="statusInfo" />
      <el-table-column label="考核情况" align="center" prop="markInfo" />
      <!--  <el-table-column label="0待审核；1活跃；2不活跃" align="center" prop="orgStatus" />
      <el-table-column label="审核时间" align="center" prop="auditTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.auditTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核教师" align="center" prop="auditId" /> -->
      <el-table-column label="操作" align="center" width="350">
        <template slot-scope="scope">
          <el-button
            style="padding: 8px; margin-right: 8px; margin-bottom: 8px"
            size="mini"
            type="primary"
            v-hasPermi="['organ:groupOrgan:setTeacherID']"
            @click="handleUpdateTeacher(scope.row)"
            >设置辅导员</el-button
          >
          <el-button
            style="padding: 8px; margin-right: 8px; margin-bottom: 8px"
            size="mini"
            type="primary"
            v-if="canWrite(scope.row)"
            v-hasPermi="['organ:classOrgan:setManager']"
            @click="handleUpdate(scope.row)"
            >设置学生管理员</el-button
          >
          <router-link
            style="margin-right: 8px; margin-bottom: 8px"
            :to="'/organ/classOrgan-data/index/' + scope.row.orgId"
            class="link-type"
          >
            <el-button
              style="padding: 8px"
              size="mini"
              type="primary"
              v-hasPermi="['organ:classOrgan:check']"
              >查看</el-button
            >
          </router-link>
          <!-- <router-link style="margin-right: 8px;margin-bottom:8px" :to="'/organ/classOrgan-dataAll/index/'+ scope.row.orgId " class="link-type">
            <el-button
              style="padding: 8px;"
              size="mini"
              type="primary"
              v-hasPermi="['organ:classOrgan:checkAll']"
            >查看全部</el-button>
          </router-link> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加辅导员 -->
    <el-dialog title="添加辅导员" :visible.sync="teacherOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="辅导员" prop="teacherId">
          <el-select
            v-model="form.teacherId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod2"
            :loading="searchLoading"
          >
            <el-option
              v-for="(item, index) in options"
              :key="index"
              :label="item.label"
              :value="item.label.substring(0, item.label.lastIndexOf('-'))"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormTeacher">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 添加或修改组织信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="学生管理员" prop="studentId">
          <el-select
            v-model="form.studentId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod"
            :loading="searchLoading"
          >
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!--修改本科生班团 -->
    <el-dialog :title="title" :visible.sync="updateOpen" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="班团名称" prop="orgName">
          <el-select multiple v-model="form.orgName" placeholder="请选择">
            <el-option label="18本科生" value="18本科生" />
            <el-option label="19本科生" value="19本科生" />
            <el-option label="20本科生" value="20本科生" />
            <el-option label="21本科生" value="21本科生" />
            <el-option label="22本科生" value="22本科生" />
          </el-select>
          <!-- <el-input @change="changeValue0($event,1)" v-model="form.orgName"  placeholder="请输入内容"></el-input> -->
        </el-form-item>
        <el-form-item label="指导单位" prop="unitCode">
          <el-select
            v-model="form.unitName"
            placeholder="请选择"
            clearable
            @change="changeValue($event, 1)"
            style="width: 240px"
          >
            <el-option
              v-for="(dict, index) in unitNameList"
              :key="index"
              :label="dict.sponsorName"
              :value="dict"
              >{{ dict.sponsorName }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item label="班级" prop="classNo">
          <el-input disabled v-model="form.classNo" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="年级" prop="grade">
          <el-input disabled v-model="form.grade" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="辅导员" prop="teacherId">
          <el-select
            v-model="form.teacherId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod2"
            :loading="searchLoading"
          >
            <el-option
              v-for="(item, index) in options"
              :key="index"
              :label="item.label"
              :value="item.label.substring(0, item.label.lastIndexOf('-'))"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="团支部书记" prop="studentId">
          <el-select
            v-model="form.studentId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod"
            :loading="searchLoading"
          >
            <el-option
              v-for="(item, index) in options"
              :key="index"
              :label="item.label"
              :value="item.label.substring(0, item.label.lastIndexOf('-'))"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormUpdateDetail">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--添加研究生 -->
    <el-dialog :title="title" :visible.sync="updateOpen2" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-form-item label="班团名称" prop="orgName">
          <el-select @change="changeValue0($event, 2)" v-model="form.orgName" placeholder="请选择">
            <el-option label="18研究生" value="18研究生" />
            <el-option label="19研究生" value="19研究生" />
            <el-option label="20研究生" value="20研究生" />
            <el-option label="21研究生" value="21研究生" />
            <el-option label="22研究生" value="22研究生" />
          </el-select>
          <!-- <el-input v-model="form.orgName"  placeholder="请输入内容"></el-input> -->
        </el-form-item>
        <el-form-item label="指导单位" prop="unitCode">
          <el-select
            v-model="form.unitName"
            placeholder="请选择"
            @change="changeValue($event, 2)"
            style="width: 240px"
          >
            <el-option
              v-for="(dict, index) in unitNameList"
              :key="index"
              :label="dict.sponsorName"
              :value="dict"
              >{{ dict.sponsorName }}</el-option
            >
          </el-select>
        </el-form-item>
        <el-form-item label="班级" prop="classNo">
          <el-input v-model="form.classNo" :disabled="true" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="年级" prop="grade">
          <el-input v-model="form.grade" :disabled="true" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="辅导员">
          <el-select
            v-model="form.teacherId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod2"
            :loading="searchLoading"
          >
            <el-option
              v-for="(item, index) in options"
              :key="index"
              :label="item.label"
              :value="item.label.substring(0, item.label.lastIndexOf('-'))"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="团支部书记" prop="studentId">
          <el-select
            v-model="form.studentId"
            filterable
            remote
            reserve-keyword
            placeholder="请输入关键词"
            :remote-method="remoteMethod"
            :loading="searchLoading"
          >
            <el-option
              v-for="(item, index) in options"
              :key="index"
              :label="item.label"
              :value="item.label.substring(0, item.label.lastIndexOf('-'))"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormUpdateDetail2">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--批量添加研究生 -->
    <el-dialog :title="title" :visible.sync="updateOpen4" width="500px" append-to-body>
      <el-form ref="form" :model="form4" :rules="rules" label-width="100px">
        <el-form-item label="班团名称" prop="orgName">
          <el-select multiple v-model="form4.orgName" placeholder="请选择">
            <el-option label="18研究生" value="18研究生" />
            <el-option label="19研究生" value="19研究生" />
            <el-option label="20研究生" value="20研究生" />
            <el-option label="21研究生" value="21研究生" />
            <el-option label="22研究生" value="22研究生" />
          </el-select>
          <!-- <el-input v-model="form.orgName"  placeholder="请输入内容"></el-input> -->
        </el-form-item>
        <el-form-item label="指导单位" prop="unitName">
          <el-select
            @change="changeUnitName"
            multiple
            v-model="form4.unitName"
            placeholder="请选择"
            style="width: 240px"
          >
            <el-option
              v-for="(dict, index) in unitNameList"
              :key="index"
              :label="dict.sponsorName"
              :value="dict.sponsorName"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="loading" type="primary" @click="submitFormUpdateDetail4"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!--批量添加本科生 -->
    <el-dialog :title="title" :visible.sync="updateOpen5" width="500px" append-to-body>
      <el-form ref="form" :model="form5" :rules="rules" label-width="100px">
        <el-form-item label="班团名称" prop="orgName">
          <el-select multiple v-model="form5.orgName" placeholder="请选择">
            <el-option label="18本科生" value="18本科生" />
            <el-option label="19本科生" value="19本科生" />
            <el-option label="20本科生" value="20本科生" />
            <el-option label="21本科生" value="21本科生" />
            <el-option label="22本科生" value="22本科生" />
          </el-select>
          <!-- <el-input v-model="form.orgName"  placeholder="请输入内容"></el-input> -->
        </el-form-item>
        <el-form-item label="指导单位" prop="unitName">
          <el-select
            @change="changeUnitName"
            multiple
            v-model="form5.unitName"
            placeholder="请选择"
            style="width: 240px"
          >
            <el-option
              v-for="(dict, index) in unitNameList"
              :key="index"
              :label="dict.sponsorName"
              :value="dict.sponsorName"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button :disabled="loading" type="primary" @click="submitFormUpdateDetail5"
          >确 定</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
        <el-upload
          ref="upload"
          :limit="1"
          accept=".xlsx, .xls"
          :headers="upload.headers"
          :action="upload.url + '?updateSupport=' + upload.updateSupport + '&schoolYear=' + ImportSchoolYearId"
          :disabled="upload.isUploading"
          :on-progress="handleFileUploadProgress"
          :on-success="handleFileSuccess"
          :auto-upload="false"
          drag
        >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
          <div class="el-upload__tip text-center" slot="tip">
            <div class="el-upload__tip" slot="tip">
              <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
            </div>
            <span>仅允许导入xls、xlsx格式文件。</span>
            <!-- <el-link
              type="primary"
              :underline="false"
              style="font-size: 12px; vertical-align: baseline"
              @click="importTemplate"
              >下载模板</el-link
            > -->
          </div>
        </el-upload>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitFileForm">确 定</el-button>
          <el-button @click="upload.open = false">取 消</el-button>
        </div>
      </el-dialog>
  </div>
</template>

<script>
import {
  listOrg,
  getOrg,
  delOrg,
  addOrg,
  addGraduate,
  batchAddGraduate,
  batchAddUnderGraduate,
  addGraduateAll,
  updateOrg,
  getstudentmanager,
  getTeacherManager,
  setstudentmanager,
  setteachermanager,
  editDefaultSchoolYear,
} from '@/api/organ/classOrgan';
import { listSponsor } from "@/api/system/sponsor";
import { getToken } from '@/utils/auth';
import { mapGetters } from 'vuex';
import { GetYearList } from '@/api/organ/organ';
export default {
  name: 'Org',
  dicts: ['sys_normal_disable', 'orgStatus'],
  computed: {
    ...mapGetters(['roles', 'name']),
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 组织信息表格数据
      orgList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orgName: null,
        unitName: null,
        unitCode: null,
        classNo: null,
        grade: null,
        type: 1,
        orgType: 1,
        teacherId: null,
        studentId: null,
        orgStatus: null,
        auditTime: null,
        auditId: null,
      },
      // 表单参数
      form: {},
      form4: {},
      form5: {},
      // 表单校验
      rules: {
        orgName: [{ required: true, message: '班团名称不能为空', trigger: 'blur' }],
        unitCode: [{ required: true, message: '指导单位不能为空', trigger: 'blur' }],
        classNo: [{ required: true, message: '班级不能为空', trigger: 'blur' }],
        grade: [{ required: true, message: '年级不能为空', trigger: 'blur' }],
        // teacherId: [{ required: true, message: '辅导员不能为空', trigger: 'blur' }],
        // studentId: [{ required: true, message: '团支部书记不能为空', trigger: 'blur' }],
      },
      updateOpen: false,
      updateOpen2: false,
      updateOpen4: false,
      updateOpen5: false,
      options: [],
      value: [],
      list: [],
      searchLoading: false,
      unitNameList: [],
      orgForm: {},
      unitNameArr: [],

      teacherOpen: false,
      schoolYearList: [],
      curSchoolYear: '',
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: '',
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: 'Bearer ' + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + '/committee/org/importOrgMember',
      },
      ImportSchoolYearId:null,
    };
  },
  created() {
    this.getYear();
    /** 系部下拉框 */
    listSponsor().then(response => {
      this.unitNameList = response.rows;
    });
    this.getList();
  },
  methods: {
    getYear() {
      GetYearList().then(response => {
        this.schoolYearList = response.rows;
        for (let i = 0; i < response.total; i++) {
          if (response.rows[i].defaultValue == '1') {
            this.curSchoolYear = response.rows[i].schoolYearId;
          }
        }
      });
    },
    /** 查询组织信息列表 */
    getList() {
      this.loading = true;
      listOrg(this.queryParams).then(response => {
        this.orgList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 判断是否能设置学生
    canWrite(row) {
      console.log(row);
      var isCanWrite = false;
      if (this.roles) {
        console.log(this.roles, 'roles');
        for (let i = 0; i < this.roles.length; i++) {
          if (
            this.roles[i] == 'student-school' ||
            this.roles[i] == 'common' ||
            this.roles[i] == 'admin'
          ) {
            isCanWrite = true;
            break;
          }
          if (this.name == row.teacherId) {
            isCanWrite = true;
            break;
          }
        }
      }
      console.log(isCanWrite, 'isCanWrite');
      return isCanWrite;
    },
    changeUnitName(item) {
      console.log(item, 'item');
      // this.form.unitName = this.form.unitName + item.unitName;
      // this.form.unitCode = this.form.unitCode + '' + item.unitCode;
    },
    // 研究生选班团
    changeValue0(event, type) {
      console.log(event, 'va00000');
      var gradeVal = event.substring(0, 2);
      this.form.grade = '20' + gradeVal;
      if (this.form.unitCode) {
        if (type == 1) {
          // this.form.classNo = event.substring(0,8);
        } else {
          this.form.classNo = gradeVal + gradeVal + this.form.unitCode + '';
        }
      }
    },
    // 指导单位赋值
    changeValue(event, type) {
      console.log(event, 'valllll');
      this.form.unitCode = event.sponsorCode;
      this.form.unitName = event.sponsorName;
      if (this.form.orgName) {
        if (type == 1) {
          // this.form.classNo = this.form.orgName.substring(0,8);
        } else {
          var gradeVal = this.form.orgName.substring(0, 2);
          this.form.classNo = gradeVal + gradeVal + this.form.unitCode + '';
        }
      }
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.updateOpen = false;
      this.updateOpen2 = false;
      this.updateOpen4 = false;
      this.updateOpen5 = false;
      this.teacherOpen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        orgId: null,
        orgName: null,
        unitName: null,
        unitCode: null,
        classNo: null,
        grade: null,
        type: 1,
        teacherId: null,
        studentId: null,
        orgStatus: '0',
        createTime: null,
        updateTime: null,
        auditTime: null,
        auditId: null,
      };
      this.form4 = this.form;
      this.form5 = this.form;
      // this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.orgId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd(num) {
      this.reset();
      if (num == 1) {
        this.updateOpen = true;
        this.title = '添加本科生班团';
      } else if (num == 2) {
        this.updateOpen2 = true;
        this.title = '添加研究生班团';
      } else if (num == 4) {
        this.updateOpen4 = true;
        this.title = '批量导入研究生';
      } else if (num == 5) {
        this.updateOpen5 = true;
        this.title = '批量导入本科生';
      } else {
        addGraduateAll().then(response => {
          if (response.code == 200) {
            this.$modal.msgSuccess('同步成功');
            this.updateOpen = false;
            this.getList();
          }
        });
      }
    },
    // 添加班团确认
    submitFormUpdateDetail() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          addOrg(this.form).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess('添加成功');
              this.updateOpen = false;
              this.getList();
            }
          });
        }
      });
    },
    // 添加研究生班团确认
    submitFormUpdateDetail2() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          addGraduate(this.form).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess('添加成功');
              this.updateOpen2 = false;
              this.getList();
            }
          });
        }
      });
    },
    // 批量导入研究生
    submitFormUpdateDetail4() {
      this.loading = true;
      var form = {};
      form.orgName = this.form4.orgName.toString();
      form.unitName = this.form4.unitName.toString();
      this.$refs['form'].validate(valid => {
        if (valid) {
          batchAddGraduate(form).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess('添加成功');
              this.loading = false;
              this.updateOpen4 = false;
              this.getList();
            }
          });
        }
      });
    },
    // 批量导入研究生
    submitFormUpdateDetail5() {
      this.loading = true;
      var form = {};
      form.orgName = this.form5.orgName.toString();
      form.unitName = this.form5.unitName.toString();
      this.$refs['form'].validate(valid => {
        if (valid) {
          batchAddUnderGraduate(form).then(response => {
            if (response.code == 200) {
              this.$modal.msgSuccess('添加成功');
              this.loading = false;
              this.updateOpen5 = false;
              this.getList();
            }
          });
        }
      });
    },
    /** 设置管理员操作 */
    handleUpdate(row) {
      this.reset();
      this.form.orgId = row.orgId;
      this.open = true;
      this.title = '设置管理员';
      /* const orgId = row.orgId; || this.ids
      getOrg(orgId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改组织信息";
      }); */
    },
    /** 设置老师管理员操作 */
    handleUpdateTeacher(row) {
      this.reset();
      this.form.orgId = row.orgId;
      this.teacherOpen = true;
      this.title = '设置辅导员';
    },
    /** 设置辅导员 */
    submitFormTeacher() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.orgId != null) {
            setteachermanager(this.form).then(response => {
              if (response.code == 200) {
                this.$modal.msgSuccess('设置成功');
                this.teacherOpen = false;
                this.getList();
              }
            });
          } else {
          }
        }
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.orgId != null) {
            setstudentmanager(this.form).then(response => {
              if (response.code == 200) {
                this.$modal.msgSuccess('设置成功');
                this.open = false;
                this.getList();
              }
            });
          } else {
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const orgId = row.orgId;
      this.$modal
        .confirm('是否确认删除组织信息编号为"' + orgId + '"的数据项？')
        .then(function () {
          return delOrg(orgId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        'system/org/export',
        {
          ...this.queryParams,
        },
        `org_${new Date().getTime()}.xlsx`
      );
    },
    /** 查询学生管理员 */
    remoteMethod(query) {
      if (query !== '') {
        this.loading = true;
        getstudentmanager(query).then(response => {
          this.loading = false;
          this.options = response.rows.filter(item => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else {
        this.options = [];
      }
    },
    /** 查询教师管理员 */
    remoteMethod2(query) {
      if (query !== '') {
        this.loading = true;
        getTeacherManager(query).then(response => {
          this.loading = false;
          this.options = response.rows.filter(item => {
            return item.label.toLowerCase().indexOf(query.toLowerCase()) > -1;
          });
        });
      } else {
        this.options = [];
      }
    },
    /** 导出
     */
    handleCommand(command) {
      this.queryParams.schoolYear = command;
      this.download(
        'committee/org/export2',
        {
          ...this.queryParams,
        },
        `org_${new Date().getTime()}.xlsx`
      );
    },
    setSchoolYear(command) {
      console.log(command);
      var param = {
        schoolYearId: command,
        defaultValue: 1,
      };
      this.$modal
        .confirm('是否确认设置"' + command + '"为当前学期？')
        .then(function () {
          return editDefaultSchoolYear(param);
        })
        .then(() => {
          this.getYear();
          this.$modal.msgSuccess('设置成功');
        })
        .catch(() => {});
      // this.queryParams.schoolYear = command;
      // this.download('committee/org/export2', {
      //   ...this.queryParams
      // }, `org_${new Date().getTime()}.xlsx`)
    },
    /** 批量删除按钮操作 */
    handleBatchDelete() {
        const orgIds = this.ids;
      if (orgIds.length > 0) {
        this.$modal
          .confirm('是否确认批量删除组织数据？')
          .then(function () {
            return delOrg(orgIds);
          })
          .then((res) => {
            this.getList();
            this.$modal.msgSuccess(res.msg);
          })
          .catch(() => {});
      } else {
        this.$modal.msgError('请选择数据！');
      }
    },
    handleImport(val){
      this.ImportSchoolYearId = val;
      console.log(val,"year")
      this.upload.title = '导入任命信息';
      this.upload.open = true;
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
          response.msg +
          '</div>',
        '导入结果',
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
  },
};
</script>
